package com.guilin.controller;

import com.guilin.common.core.domain.AjaxResult;
import com.guilin.system.service.ForumLikeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 论坛点赞Controller
 */
@RestController
@RequestMapping("/forum/like")
public class ForumLikeController {

    @Autowired
    private ForumLikeService forumLikeService;

    /**
     * 点赞主题
     * @param threadId
     * @return
     */
    @PostMapping("/thread/{threadId}")
    public AjaxResult likeThread(@PathVariable Long threadId) {
        boolean result = forumLikeService.likeThread(threadId);
        return result ? AjaxResult.success("点赞成功") : AjaxResult.error("点赞失败");
    }

    /**
     * 取消点赞主题
     * @param threadId
     * @return
     */
    @DeleteMapping("/thread/{threadId}")
    public AjaxResult unlikeThread(@PathVariable Long threadId) {
        boolean result = forumLikeService.unlikeThread(threadId);
        return result ? AjaxResult.success("取消点赞成功") : AjaxResult.error("取消点赞失败");
    }
}
